package xyz.chenyongpeng.userproviderdubbo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import xyz.chenyongpeng.entity.ZsVisitors;
import xyz.chenyongpeng.service.IZsVisitorsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import xyz.chenyongpeng.to.VisitorTo;
import xyz.chenyongpeng.userproviderdubbo.mapper.ZsVisitorsMapper;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 游客表 服务实现类
 * </p>
 *
 * @author chenyongpeng
 * @since 2018-12-10
 */
public class ZsVisitorsService extends ServiceImpl<ZsVisitorsMapper, ZsVisitors> implements IZsVisitorsService {

    @Autowired
    private ZsVisitorsMapper visitorsMapper;

    @Override
    public List<VisitorTo> getListByUId(Map<String, Object> parms) {
        String[] page = parms.get("limit").toString().split(",");
        parms.put("start", Integer.parseInt(page[0]));
        parms.put("end", Integer.parseInt(page[1]));
        return visitorsMapper.getListByUId(parms);
    }

    @Override
    public int addVisitors(Map<String,Object> parms) {
        ZsVisitors zsVisitors = visitorsMapper.selectOne(new QueryWrapper<ZsVisitors>().eq("v_id_card", parms.get("v_id_card"))
        .eq("v_id_type", parms.get("v_id_type"))
        .eq("v_truename", parms.get("v_truename"))
        .eq("u_id", parms.get("u_id")));

        zsVisitors.setLastUpdateTime((int)System.currentTimeMillis()/1000);
        if (zsVisitors != null){
            visitorsMapper.updateById(zsVisitors);
        }else {
            visitorsMapper.insert(zsVisitors);
        }
        return 1;
    }
}
